package com.kasax.sdk.map;

import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.location.Location;
import android.location.LocationManager;

import androidx.core.app.ActivityCompat;

import com.kasax.sdk.map.utils.LocationUtils;

public class GedeServiceImpl implements IMyGedeService {
    private Context appContext;
    private String pkgName;
    private String business;

    public GedeServiceImpl(Context context, String pkgName, String business) {
        this.appContext = context;
        this.pkgName = pkgName;
        this.business = business;
    }

    @Override
    public Location getCurrentLocation() {
        try {
            LocationManager locationManager = (LocationManager) appContext.getSystemService(Context.LOCATION_SERVICE);
            if (ActivityCompat.checkSelfPermission(appContext, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &&
                    ActivityCompat.checkSelfPermission(appContext, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                return locationManager.getLastKnownLocation("wifi");
            }

        } catch (Exception e) {
            return null;
        }
        return null;
    }

    @Override
    public boolean isFakeLocation(Location location) {
        return LocationUtils.isFakeLocation();
    }
}
